﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Rhino.Mocks;
using Affirma.ThreeSharp.Wrapper;
using Dokan;
using System.IO;

namespace CloudDrive.S3.Tests
{
    [TestFixture]
    public class CreateFileMethodTests
    {
        const string _BucketName = "BUCKET_NAME";
        string _BucketListWithSingleTestFile;
        [SetUp]
        public void Setup()
        {
            _BucketListWithSingleTestFile = File.ReadAllText("ListBucketWithSingleTestFile.xml");
        }
        [Test]
        public void CreateFileReturnsSuccess()
        {
            string fileName = "FileName.txt";
            DokanFileInfo fileInfo = new DokanFileInfo();
            var threeSharp = MockRepository.GenerateMock<IThreeSharpWrapper>();
            var proxy = new S3Proxy(threeSharp, _BucketName);
            S3DriveOperations operations = new S3DriveOperations(proxy);
            var result = operations.CreateFile(fileName, System.IO.FileAccess.Read, System.IO.FileShare.None, System.IO.FileMode.Create, System.IO.FileOptions.None, fileInfo);
            Assert.AreEqual(DokanNet.DOKAN_SUCCESS, result);
        }
        [Test]
        public void ReturnsFileExistsErrorIfFileExistsAndOptionIsCreateNew()
        {
            string fileName = "TestFile.txt";
            DokanFileInfo fileInfo = new DokanFileInfo();
            var threeSharp = MockRepository.GenerateMock<IThreeSharpWrapper>();
            S3Proxy proxy = new S3Proxy(threeSharp, _BucketName);
            threeSharp.Stub(x => x.ListBucket(null))
                .IgnoreArguments()
                .Return(_BucketListWithSingleTestFile);
            S3DriveOperations operations = new S3DriveOperations(proxy);
            int result = operations.CreateFile(fileName, System.IO.FileAccess.Read, System.IO.FileShare.None, System.IO.FileMode.CreateNew, System.IO.FileOptions.None, fileInfo);
            Assert.AreEqual(DokanNet.ERROR_FILE_EXISTS, result);
        }
    }
}
